package sellingapartment

class FacilityController {
	static allowedMethods = [create:'POST', update:'POST', delete:'POST', edit:'GET']
	def facilityService
	
	/**
	 * Request show 
	 * @return
	 */
	def index() {
		def message = params.get("message")
		def facilities = facilityService.getAllFacilities()
		[facilities:facilities, message:message]
	}
	/**
	 * Return a persisted instance of student information by {@code name}
	 * and {@code description}.
	 * 
	 * @param name student's name
	 * @param description
	 * @return a persisted instance
	 */
	def create(String name, String description) {
		println name + description
		return facilityService.saveFacility(params)
	}
	def edit(Long id){
		Facility facility = facilityService.getFacility(id)
		if(!facility){
			render "Can not found Facility."
		}
		else {
			[facility:facility]
		}
	}
	def update() {
		def message = ""
		if(facilityService.updateFacility(params)){
			message = "Update successfully."
		}
		else{
			message = "Update unsuccessfully."
		}
		redirect (action:"index", params:[message:message])
	}
	def delete(Long id) {
		def deleted = false
		if(facilityService.deleteFacility(id)){
			deleted = true
		}
		else{
			deleted = false
		}
		render deleted
	}
}
